package com.risenb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.risenb.bean.PermissionRole;
import com.risenb.bean.Role;
import com.risenb.dao.ManagerMapper;
import com.risenb.dao.ModuleMapper;
import com.risenb.dao.RoleMapper;
import com.risenb.service.PermissionRoleService;
import com.risenb.service.RoleService;

@Service
public class RoleServiceImpl implements RoleService {
	
	@Autowired
	RoleMapper roleMapper;
	
	@Autowired
	ModuleMapper moduleMapper;
	
	@Autowired
	PermissionRoleService permissionRoleService;
	
	@Autowired
	ManagerMapper managerMapper;
	
	@Override
	public int removeRoleById(Integer id) {
		return roleMapper.removeRoleById(id);
	}

	@Override
	public int createRole(Role record) {
		return roleMapper.createRole(record);
	}

	@Override
	public Role queryRoleById(Integer id) {
		Role role = roleMapper.queryRoleById(id);
		if(role!=null){
		role.setPr(permissionRoleService.queryPermissionRoleByRoleById(role.getId()));
		}
		return role;
	}

	@Override
	public int modifyRoleById(Role record) {
		return roleMapper.modifyRoleById(record);
	}

	@Override
	public List<Role> queryAll(Role role) {
		List<Role> roles = roleMapper.queryAll(role);
		for (int i = 0; i < roles.size(); i++) {
			roles.get(i).setOperatorM(managerMapper.queryManagerById(roles.get(i).getOperator()));
			List<PermissionRole> ps = permissionRoleService.queryPermissionRoleByRoleById(roles.get(i).getId());
			roles.get(i).setPr(ps);
		}
		return roles;
	}

	@Override
	public int removeRoleByIds(List<String> ids) {
		return roleMapper.removeRoleByIds(ids);
	}

}
